/* indent size: 2 */

module.exports = app => {
  const DataTypes = app.Sequelize;

  const Shoppingcarts = app.model.define('shoppingcarts', {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      comment: '购物车id'
    },
    count: {
      type: DataTypes.INTEGER,
      // allowNull: false,
      comment: '购物车商品数量'
    },
    uid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '购物车所属用户id',
      references: {
        model: 'users',
        key: 'id'
      }
    },
    createdAt: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: '创建时间'
    },
    updatedAt: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: '更新时间'
    }
  }, {
    tableName: 'shoppingcarts'
  });

  Shoppingcarts.associate = function () {

    //一个购物车属于一个用户
    app.model.Shoppingcarts.belongsTo(app.model.Users, {
      foreignKey: 'uid',//定义联结关系中源模型的 key
      targetKey: 'id'
    });
  }

  return Shoppingcarts;
};
